package textFile;

import java.io.*;


// Reader读文件
public class ReaderTest {
    public static void main1(String[] args) {
        try (Reader reader = new FileReader("D:/work/test.txt")){
            while (true){
                int r = reader.read();
                if(r == -1){
                    break;
                }
                System.out.println(r);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 使用字符缓冲区读取文件
    public static void main(String[] args) {
        // 注意：把FileReader的对象传给字符缓冲区BufferReader
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader("D:/work/test.txt"))){
            String line;
            // 注意：当读完文件时，line就是等于null
            while ((line = bufferedReader.readLine()) != null){
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
